﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsDataChiNhanh
    {
        private string mDbName = "";
        private string mDbPass = "";
        private string mDbUser = "";
        private string mKhoaKho = "";
        private string mMa = "";
        private string mTenAnh = "";
        private string mTenMayChu = "";
        private string mTenViet = "";

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM HT_DataChiNhanh WHERE Ma = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mMa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mTenViet = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mTenAnh = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mTenMayChu = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mDbUser = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mDbPass = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mDbName = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKho = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag2;
            IDataParameter[] commandParameters = new IDataParameter[11];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Ma", DbType.Int64, ParameterDirection.Input, this.mMa);
                commandParameters[1] = DBHelper.createParameter("@TenViet", DbType.Int64, ParameterDirection.Input, this.mTenViet);
                commandParameters[2] = DBHelper.createParameter("@TenAnh", DbType.Int64, ParameterDirection.Input, this.mTenAnh);
                commandParameters[3] = DBHelper.createParameter("@TenMayChu", DbType.Int64, ParameterDirection.Input, this.mTenMayChu);
                commandParameters[4] = DBHelper.createParameter("@DbUser", DbType.Int64, ParameterDirection.Input, this.mDbUser);
                commandParameters[5] = DBHelper.createParameter("@DbPass", DbType.Int64, ParameterDirection.Input, this.mDbPass);
                commandParameters[6] = DBHelper.createParameter("@DbName", DbType.Int64, ParameterDirection.Input, this.mDbName);
                bool flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "HT_sp_DataChiNhanh", commandParameters) > 0;
                flag2 = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag2 = false;
                ProjectData.ClearProjectError();
                return flag2;
                ProjectData.ClearProjectError();
            }
            return flag2;
        }

        public DataTable ShowList()
        {
            string commandText = " SELECT Ma, TenViet As Ten FROM HT_DataChiNhanh ";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public string DbName
        {
            get
            {
                return this.mDbName;
            }
            set
            {
                this.mDbName = value;
            }
        }

        public string DbPass
        {
            get
            {
                return this.mDbPass;
            }
            set
            {
                this.mDbPass = value;
            }
        }

        public string DbUser
        {
            get
            {
                return this.mDbUser;
            }
            set
            {
                this.mDbUser = value;
            }
        }

        public string KhoaKho
        {
            get
            {
                return this.mKhoaKho;
            }
            set
            {
                this.mKhoaKho = value;
            }
        }

        public string Ma
        {
            get
            {
                return this.mMa;
            }
            set
            {
                this.mMa = value;
            }
        }

        public string TenAnh
        {
            get
            {
                return this.mTenAnh;
            }
            set
            {
                this.mTenAnh = value;
            }
        }

        public string TenMayChu
        {
            get
            {
                return this.mTenMayChu;
            }
            set
            {
                this.mTenMayChu = value;
            }
        }

        public string TenViet
        {
            get
            {
                return this.mTenViet;
            }
            set
            {
                this.mTenViet = value;
            }
        }
    }
}

